﻿using Halcon二次开发.Controller.多文本显示;
using Halcon二次开发.Controller.数据加载与保存;
using Halcon二次开发.Model;
using Halcon二次开发.Model.储存每个Controller的单例对象;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.自定义控件;
using Halcon二次开发.View.卡尺;
using Halcon二次开发.View.找圆_线_矩形;
using Halcon二次开发.View.相机;
using Halcon二次开发.View.结果分析工具;
using Halcon二次开发.View.距离转换工具;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.多文本显示工具
{
    public partial class MessageBoxStringsForms : Form
    {
        public string nodeName;
        public ShowTextController controller = null;
        HwindowFlowNodeUrseControl hwindowFlowNode;
        public MessageBoxStringsForms(string name,HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.nodeName = name;
            this.hwindowFlowNode = hwindowFlowNode;
            InitializeComponent();
            controller = new ShowTextController(this, hwindowFlowNode);
            comboBox1.SelectedIndex = 0;
            comboBox4.SelectedIndex =1;
        }
        public void GetName(string nodeName)
        {
            this.nodeName = nodeName;
        }
        /// <summary>
        /// 存储找圆找线卡尺窗体的对象
        /// </summary>
        public List<Form> formsList = new List<Form>();




        /// <summary>
        /// 反射调用的方法，请不要修改
        /// </summary>
        /// <param name="path">Json文件的路径</param>
        /// <param name="addres">节点</param>
        public void SetJsonPaths(string path, string addres)
        {
            string paths = path + "\\" + "界面数据\\" + nodeName + "\\" + addres + "数据.json";
            //调用存储方法
            new LoadData().LoadDatas(paths, this);
        }
        private void MessageBoxStringsForms_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (TreeNode item in hwindowFlowNode.treeView1.Nodes)
                {
                    if (item.Name.Contains("相机"))
                    {
                        controller.HideIntputImage = (item.Tag as CamerForm).controller.HideOutputImage;
                    }
                }

                //小运行时获取卡尺工具的数据 ，结果距离转换工具的数据，结果分析工具的数据
                controller.HideIntputArrayDistances = (((this.Parent as TabPage).Parent as TabControl).GetControl(1).Tag as DistanceToolForm).controller.HideOutputArrayDistances;
                controller.HideIntputArrayRows = (((this.Parent as TabPage).Parent as TabControl).GetControl(0).Tag as PreciseCaliper).controller.HideOutputArrayRows;
                controller.HideIntputArrayColumns = (((this.Parent as TabPage).Parent as TabControl).GetControl(0).Tag as PreciseCaliper).controller.HideOutputArrayColumns;
                if ((((this.Parent as TabPage).Parent as TabControl).GetControl(2).Tag as AnalyseResultForms).comboBox1.Text.Trim() == "打开")
                {
                    controller.HideIntputResults = (((this.Parent as TabPage).Parent as TabControl).GetControl(2).Tag as AnalyseResultForms).controller.HideOutputResults;
                }
                else
                {
                    controller.HideIntputResults.Clear();
                }

                if (comboBox4.Text.Trim() == "打开")
                {
                    controller.Tool_Run();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("坐标转换异常：" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            if (!(comboBox1.Text == "跟随" || comboBox1.Text == "左边" || comboBox1.Text == "右边"))
            {
                comboBox1.Text = "跟随";
            }
        }

        private void comboBox2_TextChanged(object sender, EventArgs e)
        {
            if (!(comboBox2.Text == "red" || comboBox2.Text == "orange" || comboBox2.Text == "yellow" || comboBox2.Text == "blue" || comboBox2.Text == "green" ||comboBox2.Text == "white" || comboBox2.Text == "black"))
            {
                comboBox2.Text = "green";
            }
        }

        private void comboBox3_TextChanged(object sender, EventArgs e)
        {
            if (!(comboBox3.Text == "red" || comboBox3.Text == "orange" || comboBox3.Text == "yellow" || comboBox3.Text == "blue" || comboBox3.Text == "green" ||comboBox3.Text== "white"||comboBox3.Text=="black"))
            {
                comboBox3.Text = "red";
            }
        }

        /// <summary>
        /// 反射调用该方法更新窗体句柄
        /// </summary>
        /// <param name="hwindowFlowNode"></param>
        public void PushHWindon(HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.hwindowFlowNode = hwindowFlowNode;
            controller.hwindowFlowNode = hwindowFlowNode;
            controller.hw = hwindowFlowNode.hSmartWindowControl1;
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox4.Text.Trim() == "打开")
            {
                tabControl1.Enabled = true;
            }else if (comboBox4.Text.Trim() == "关闭")
            {
                tabControl1.Enabled = false;
            }
        }
    }
}
